package logic

import (
	"context"
	"renting-demo/user_srv/user"

	"renting-demo/api/internal/svc"
	"renting-demo/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserEditAvatarLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserEditAvatarLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserEditAvatarLogic {
	return &UserEditAvatarLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserEditAvatarLogic) UserEditAvatar(req *types.UserEditAvatarReq) (resp *types.Data, err error) {
	// todo: add your logic here and delete this line
	res, err := l.svcCtx.UserServer.UserModifyAvatar(context.Background(), &user.ModifyAvatarRequest{
		UserID:    int64(req.UserId),
		AvatarUrl: req.Imgs,
	})
	if err != nil {
		return &types.Data{
			Code:    500,
			Message: err.Error(),
		}, nil
	}
	if res.Status == 0 {
		return &types.Data{
			Code:    500,
			Message: "修改失败",
		}, nil
	}

	return &types.Data{
		Code:    0,
		Message: "修改成功",
	}, nil
}
